<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		#div1{width: 100px; height: 100px; background-color: red;position: absolute; left:200px; top: 50px;}
		#div2{width: 1px; height: 300px; background-color: #000;position: absolute; left: 600px; top: 0;}
	</style>
	<script type="text/javascript">
	window.onload = function (){
		var oDiv = document.getElementById('div1');
		var iSpeed = 0;

		setInterval(function (){
			if (oDiv.offsetLeft < 600) {
				iSpeed +=2;
			} else{
				iSpeed -=2;
			};
			oDiv.style.left = oDiv.offsetLeft + iSpeed + 'px';
		},30)
	}
	</script>
</head>
<body>
	<div id="div1"></div>
	<div id="div2"></div>
</body>
</html>